<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>hi 2048</title>
  <style>
    #button {
      width: 100px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border: 1px solid #ddd;
      border-radius: 5px;
    }
    #button:hover{
      background-color: #ddd;
    }
  </style>
</head>
<body>
  <div id="button">
    2
  </div>
  <script>
    // 1. 选择元素
    var elementA = document.getElementById('button')
    // 2. 打印元素
    console.log(elementA)
    // 3. 设置点击时候的行为
    document.onkeypress = function(event) {
      var key = event.key
      // 3.1 当我按 w 的时候, 就✖️2
      if (key === 'w') {
        var text = elementA.innerText
        var num = parseInt(text)
        num *= 2 // num = num * 2
        elementA.innerText = num
      } else {
        // 3.2 当我按 s 的时候就➗2
        var text = elementA.innerText
        var num = parseInt(text)
        num /= 2 // num = num * 2
        elementA.innerText = num
      }
    }
  </script>
</body>
</html>